package ext.sim.forces;

import ext.sim.Body;
import java.util.ArrayList;
import math.vec3;
import static math.vec3.*;

/** Attractive force that pulls all bodies towards an axis with 
    directions only in the perpendicular planes of the axis. */
public class ForceVortexAxial implements Force
{
    
    private ArrayList<Body> rBodies;
    
    private vec3 mPoint;
    
    private vec3 mAxis;
    
    private double mStrength;
    
    
    public ForceVortexAxial(
            ArrayList<Body> aBodies, 
            vec3 aPoint, 
            vec3 aAxis, 
            double aStrength)
    {
        this.rBodies = aBodies;
        this.mPoint = aPoint;
        this.mAxis = norm(aAxis);
        this.mStrength = aStrength;
    }
    
    
    public void apply()
    {
        for (Body b : this.rBodies)
        {
            vec3 toX = sub(b.mX, this.mPoint);
            vec3 axisProj = proj(toX, this.mAxis);
            vec3 planarX = sub(toX, axisProj); // Remove the vector along the axis.
            
            vec3 fAxial = mul(-this.mStrength, planarX);
            
            b.mF.add(fAxial);
        }
    }
    
}
